package com.ymk.cmd;

import com.ymk.base.cmd.ACmd;
import com.ymk.base.cmd.CmdSign;
import com.ymk.base.mybatis.Pagination;
import com.ymk.base.utlis.ParamsBuilder;
import com.ymk.bo.mch.MchBO;
import com.ymk.core.code.cmd.MchCmdCode;
import com.ymk.service.IMchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Service
public class MchListCmd extends ACmd {

    @Override
    public CmdSign executeSop(HttpServletRequest request, CmdSign sign) throws Exception {
        CmdSign respSign = new CmdSign(sign);
        MchBO reqData = super.getData(sign, MchBO.class);

        ParamsBuilder paramsBuilder = ParamsBuilder.newBuild()
                .addParam("title", reqData.getTitle())
                .addParam("status", reqData.getStatus())
                .addParam("loadMchUser",true)
                .setReturnStruct(sign.getReturnStruct());

        Pagination pagination = sign.buildPage();
        pagination.setParams(paramsBuilder.build());

        List<MchBO> respDataList = this.mchService.listForPage(pagination);

        respSign.setPageInfo(pagination);
        respSign.setSource(super.getSource(respDataList));

        return respSign;
    }

    @Override
    public String getCmdCode() {
        return MchCmdCode.MCH_LIST;
    }

    @Autowired
    private IMchService mchService;
}